// point2.h
// Written by Sergei Sokov

#ifndef __POINT2_H
#define __POINT2_H

#include "3d/tuple2.h"
#include <math.h>  // sqrt()

template<class T>
class Point2_ : public Tuple2_<T> {
 public:
  Point2_(void) {
  }

  Point2_(Tuple2_<T> &t) {
    x=t.x; y=t.y;
  }

  Point2_(T xx,T yy) {
    x=xx; y=yy;
  }

  T distanceSquared(const Point2_ &p) const {
    return (p.x-x)*(p.x-x) + (p.y-y)*(p.y-y);
  }

  T distanceSquared(const T *p) const {
    return (p[0]-x)*(p[0]-x) + (p[1]-y)*(p[1]-y);
  }

  T distanceSquared(T xx,T yy) const {
    return (x-xx)*(x-xx) + (y-yy)*(y-yy);
  }

  T distanceToOriginSquared(void) const {
    return x*x + y*y;
  }

  T distance(const Point2_ &p) const {
    return (T)sqrt(distanceSquared(p));
  }

  T distance(const T *p) const {
    return (T)sqrt( (p[0]-x)*(p[0]-x) + (p[1]-y)*(p[1]-y) );
  }

  T distance(T xx,T yy,T zz) const {
    return (T)sqrt( (x-xx)*(x-xx) + (y-yy)*(y-yy) );
  }

  T distanceToOrigin(void) const {
    return (T)sqrt( x*x + y*y );
  }

  void rotate( T cosA, T sinA ) {
    set( cosA*x - sinA*y,
         sinA*x + cosA*y );
  }
};


typedef Point2_<float>  Point2f;
typedef Point2_<double> Point2d;

#endif

/* eof */
